
package com.test;

import java.io.File;


import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.TextView;


public class SMILPlayer extends Activity
{
    private Handler mHandler = new Handler();


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.player);

        TextView result = (TextView) this.findViewById(R.id.result);
        try
        {
            File sdRoot = Environment.getExternalStorageDirectory();

            if (sdRoot.canRead())
            {
                Bundle smilFile = getIntent().getExtras();
                SMILMessage value;
                if (smilFile != null)
                {
                    value = (SMILMessage) smilFile.getSerializable("message");

                    // File newXmlFile = new File(sdRoot + value);
                    //
                    // FileInputStream fis = new FileInputStream(newXmlFile);
                    //
                    // SMILMessage smilMessage = SMILReader.parseMessage(fis);
                    SMILTextComponent component = (SMILTextComponent) value.getSeriesList().get(0).getComponentList()
                            .get(0);
                    result.setText(component.getText());

                    mHandler.postDelayed(removeTask, component.getDuration() * 1000);
                }
            }
        }
        catch (Exception e)
        {
            Log.e("Exception", "error occurred while creating xml file", e);
            result.setText("File could not be written.");
        }
    }

    private Runnable removeTask = new Runnable()
    {
        public void run()
        {
            View result = findViewById(R.id.result);
            result.setVisibility(View.INVISIBLE);

        }
    };
}
